﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using System.Data.Entity;

namespace AnalysisApp.Web.Models
{
    public class ConfigurationModel
    {

        [Display(Name = "Connection String")]
        [DefaultValue(DEFAULT_OlapConnectionString)]
        public string OlapConnectionString { get; set; }

        [DefaultValue(DEFAULT_MdxQuery)]
        [ScaffoldColumn(false)]
        public string MdxQuery { get; set; }

        [Display(Name = "Sample Cube Name")]
        [DefaultValue(DEFAULT_SampleCubeName)]
        public string SampleCubeName { get; set; }

        [DefaultValue(DEFAULT_UpdateScript)]
        [ScaffoldColumn(false)]
        public string UpdateScript { get; set; }

        [DefaultValue(DEFAULT_MdxDesignerLayout)]
        [Display(Name = "MdxDesignerLayout")]
        [ScaffoldColumn(false)]
        public string MdxDesignerLayout { get; set; }

        public ConfigurationModel()
        {
            OlapConnectionString = DEFAULT_OlapConnectionString;
            MdxQuery = DEFAULT_MdxQuery;
            SampleCubeName = DEFAULT_SampleCubeName;
            UpdateScript = DEFAULT_UpdateScript;
            MdxDesignerLayout = DEFAULT_MdxDesignerLayout;
        }


        private const string DEFAULT_OlapConnectionString =
           // @"Provider=MSOLAP.4;Data Source=|DataDirectory|\Finance.cub";
        @"Provider=MSOLAP.4;DATA SOURCE=DPP-813\SQL2008R2;CATALOG=ADVENTURE WORKS DW";

        private const string DEFAULT_SampleCubeName = "Finance";
        private const string DEFAULT_UpdateScript = "--You need to enable WriteBack ability for your cube first.";

        private const string DEFAULT_MdxQuery = @"SELECT
                                                    DRILLDOWNMEMBER
                                                    ( Hierarchize ( [Account].[Account].Levels ( 0 ).Members )
                                                    , [Account].[Account].[All Accounts]
                                                    )
                                                    DIMENSION PROPERTIES PARENT_UNIQUE_NAME , HIERARCHY_UNIQUE_NAME , CUSTOM_ROLLUP , UNARY_OPERATOR , KEY0 ON 0
                                                , DRILLDOWNMEMBER
                                                    ( Hierarchize ( [Date].[Month of Year].Levels ( 0 ).Members )
                                                    , [Date].[Month of Year].[All Periods]
                                                    )
                                                    DIMENSION PROPERTIES PARENT_UNIQUE_NAME , HIERARCHY_UNIQUE_NAME , CUSTOM_ROLLUP , UNARY_OPERATOR , KEY0 ON 1
                                                FROM [Finance]
                                                WHERE [Measures].[Amount]
                                                CELL PROPERTIES BACK_COLOR , CELL_ORDINAL , FORE_COLOR , FONT_NAME , FONT_SIZE , FONT_FLAGS , FORMAT_STRING , VALUE , FORMATTED_VALUE , UPDATEABLE
                                                ";


        private const string DEFAULT_MdxDesignerLayout = @"<?xml version='1.0' encoding='utf-8'?>
                        <MdxLayoutWrapper xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
                          <CubeName>Finance</CubeName>
                          <SubCube />
                          <Filters />
                          <Rows>
                            <AreaItemWrapper xsi:type='Hierarchy_AreaItemWrapper'>
                              <CustomProperties>
                                <PropertyInfo>
                                  <Name>DIMENSION_CAPTION</Name>
                                  <Value xsi:type='xsd:string'>Date</Value>
                                </PropertyInfo>
                                <PropertyInfo>
                                  <Name>CUBE_CAPTION</Name>
                                  <Value xsi:type='xsd:string'>Finance</Value>
                                </PropertyInfo>
                              </CustomProperties>
                              <Caption>Month of Year</Caption>
                              <CompositeFilter>
                                <IsUsed>false</IsUsed>
                                <MembersFilter>
                                  <IsUsed>false</IsUsed>
                                  <SelectedInfo />
                                  <FilterSet />
                                </MembersFilter>
                                <Filter>
                                  <IsUsed>false</IsUsed>
                                  <CurrentFilter>LabelFilter</CurrentFilter>
                                  <TopFilter>
                                    <FilterType>Top</FilterType>
                                    <Count>10</Count>
                                    <FilterTarget>Items</FilterTarget>
                                    <MeasureUniqueName />
                                  </TopFilter>
                                  <ValueFilter>
                                    <FilterType>Equal</FilterType>
                                    <Num1>0</Num1>
                                    <Num2>1</Num2>
                                    <MeasureUniqueName />
                                  </ValueFilter>
                                  <LabelFilter>
                                    <FilterType>Equal</FilterType>
                                    <Text1 />
                                    <Text2 />
                                    <LevelPropertyName />
                                  </LabelFilter>
                                </Filter>
                              </CompositeFilter>
                              <UniqueName>[Date].[Month of Year]</UniqueName>
                            </AreaItemWrapper>
                          </Rows>
                          <Columns>
                            <AreaItemWrapper xsi:type='Hierarchy_AreaItemWrapper'>
                              <CustomProperties>
                                <PropertyInfo>
                                  <Name>DIMENSION_CAPTION</Name>
                                  <Value xsi:type='xsd:string'>Account</Value>
                                </PropertyInfo>
                                <PropertyInfo>
                                  <Name>CUBE_CAPTION</Name>
                                  <Value xsi:type='xsd:string'>Finance</Value>
                                </PropertyInfo>
                              </CustomProperties>
                              <Caption>Account</Caption>
                              <CompositeFilter>
                                <IsUsed>false</IsUsed>
                                <MembersFilter>
                                  <IsUsed>false</IsUsed>
                                  <SelectedInfo />
                                  <FilterSet />
                                </MembersFilter>
                                <Filter>
                                  <IsUsed>false</IsUsed>
                                  <CurrentFilter>LabelFilter</CurrentFilter>
                                  <TopFilter>
                                    <FilterType>Top</FilterType>
                                    <Count>10</Count>
                                    <FilterTarget>Items</FilterTarget>
                                    <MeasureUniqueName />
                                  </TopFilter>
                                  <ValueFilter>
                                    <FilterType>Equal</FilterType>
                                    <Num1>0</Num1>
                                    <Num2>1</Num2>
                                    <MeasureUniqueName />
                                  </ValueFilter>
                                  <LabelFilter>
                                    <FilterType>Equal</FilterType>
                                    <Text1 />
                                    <Text2 />
                                    <LevelPropertyName />
                                  </LabelFilter>
                                </Filter>
                              </CompositeFilter>
                              <UniqueName>[Account].[Account]</UniqueName>
                            </AreaItemWrapper>
                          </Columns>
                          <Data>
                            <AreaItemWrapper xsi:type='Measure_AreaItemWrapper'>
                              <CustomProperties />
                              <Caption>Amount</Caption>
                              <UniqueName>[Measures].[Amount]</UniqueName>
                            </AreaItemWrapper>
                          </Data>
                          <CalculatedMembers />
                          <CalculatedNamedSets />
                        </MdxLayoutWrapper>
                        ";

    }


}